package conteoller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.miaodiyun.httpApiDemo.IndustrySMS;

import biz.CustomerBiz;
import entity.CustomertbEntity;
@WebServlet("/Verification_code")
public class Verification_code extends BaseServlet{
	CustomerBiz khb = new CustomerBiz();
		static int x=0;
		static String numb=null;
	public void SMSlogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		PrintWriter pw=response.getWriter();
		String userid = request.getParameter("userid");
		IndustrySMS.execute(userid);
		numb=String.valueOf(x);
	}
	
	
	public static int GetCode() {
		x=(int)((Math.random()*9+1)*100000);
		return x;
	}
	public String Verification (HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
		String userid= request.getParameter("userid");
		List<CustomertbEntity> list =null;
		list=khb.login(userid);
		if(list.size()==0) {
			response.getWriter().write("璐﹀彿鍙敤锛�");
		}
		else {
			response.getWriter().write("璐﹀彿宸叉敞鍐岋紒");
		}
		return null;
		}
	public String Verification_bd(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
		String userid= request.getParameter("userid");
		String username = request.getParameter("username");
		String userpassword = request.getParameter("userpassword");
		String usermail = request.getParameter("usermail");
		String Verification = request.getParameter("Verification");
		Verification_code vc = new Verification_code();
		PrintWriter pw=response.getWriter();
		if(Verification.equals(vc.numb)) {
			if(khb.user_registered(userid, username, userpassword, usermail)>0) {
				response.sendRedirect("login.jsp");
				pw.write("<script language='javascript'>alert('娉ㄥ唽鎴愬姛锛�')</script>");
			}
			else {
				pw.write("<script language='javascript'>alert('娉ㄥ唽澶辫触锛�')</script>");
			}
		}
		else {
			System.out.println("aaaaaaaa");
		}
		return null;
		}
	}
